package com.example.springboot.service.impl;

import com.example.springboot.mapper.RepairMapper;
import com.example.springboot.pojo.Repair;
import com.example.springboot.service.FileService;
import com.example.springboot.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.example.springboot.util.TimeUtil.getNow;


@Service
public class RepairServiceImpl implements RepairService {

    @Autowired
    private RepairMapper repairMapper;
    @Autowired
    private FileService fileService;

    @Override
    public Repair findRepair(Integer id) {
        return repairMapper.findRepair(id);
    }

    @Override
    public Repair[] getAllRepair() {
        return repairMapper.getAllRepair();
    }

    @Override
    public Repair[] getByRoomNumber(String roomNumber) {
        return repairMapper.getByRoomNumber(roomNumber);
    }

    @Override
    public Repair[] getByWorkerId(String workerId) {
        return repairMapper.getByWorkerId(workerId);
    }

    @Override
    public void deleteRepair(Integer id) {
        String url = repairMapper.findRepair(id).getPhoto();
        fileService.deleteFile(url);
        repairMapper.deleteRepair(id);
    }

    @Override
    public void passRepair(Integer id,String workerId) {
        repairMapper.passRepair(id,workerId);
    }

    @Override
    public void finishRepair(Integer id) {
        repairMapper.finishRepair(id);
    }

    @Override
    public void addRepair(String roomNumber, String detail,String photo) {
        repairMapper.addRepair(roomNumber,detail,photo,getNow());
    }
}
